<script lang="ts" setup>
import useUpload from '@renderer/composables/useUpload'
import formButton from './formButton.vue'
const { uploadImage } = useUpload()

const props = withDefaults(
  defineProps<{
    name?: string
  }>(),
  { name: 'file' },
)
const emit = defineEmits<{
  (e: 'finish', fileInfo: UploadResult): void
}>()
//上传到服务器
const upload = async (file: any) => {
  const form = new FormData()
  form.append(props.name, file)
  const fileInfo = await uploadImage(form)
  emit('finish', fileInfo)
}

const request = async (options: any) => {
  upload(options.file)
}
</script>

<template>
  <el-upload action="" :http-request="request" :show-file-list="false">
    <formButton>上传</formButton>
  </el-upload>
</template>
